package com.cx.controller;

import com.cx.dto.PageInfoResult;
import com.cx.pojo.Goods;
import com.cx.service.GoodListService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import java.math.BigDecimal;
import java.util.List;

@Controller
@RequestMapping("goodlist")
public class GoodListController {

    @Autowired
    GoodListService goodListService;

    @RequestMapping("selectall")
    public ModelAndView SelectAll(PageInfoResult pageInfoResult,String goodName){
        ModelAndView modelAndView = new ModelAndView();
//        pageInfoResult = goodListService.selectAllByPage(pageInfoResult);
//        modelAndView.addObject("pageInfoResult",pageInfoResult);
//        modelAndView.addObject("goodsList",pageInfoResult.getDataList());
        modelAndView.addObject("goodName",goodName);
        modelAndView.setViewName("goodlist");
        return modelAndView;
    }

    @RequestMapping("selectallbypage")
    @ResponseBody
    public PageInfoResult SelectAllByPage(PageInfoResult pageInfoResult){
        pageInfoResult = goodListService.selectAllByPage(pageInfoResult);
        //List<Goods> goodsList = pageInfoResult.getDataList();
        //return goodsList;
        return pageInfoResult;
    }

//    @RequestMapping("selectbygoodnameandpage")
//    @ResponseBody
//    public PageInfoResult<Goods> SelectByGoodNameAndPage(PageInfoResult<Goods> pageInfoResult, String goodName){
//        pageInfoResult = goodListService.selectByGoodNameAndPage(pageInfoResult,goodName);
//        //List<Goods> goodsList = pageInfoResult.getDataList();
//        //return goodsList;
//        return pageInfoResult;
//    }

    @RequestMapping("selectbyselectiveandpage")
    @ResponseBody
    public PageInfoResult SelectBySelectiveAndPage(PageInfoResult pageInfoResult,String goodName,Integer type, Integer types, BigDecimal lowPrice,BigDecimal upPrice){
        pageInfoResult = goodListService.selectBySelectiveAndPage(pageInfoResult,goodName,type,types,lowPrice,upPrice);
        return pageInfoResult;
    }

}
